package com.lsy.android.pingpang.view;

import com.lsy.android.pingpang.R;
import com.lsy.android.pingpang.tool.MyTimer;

import android.app.Activity;
import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class GameOverView extends FrameLayout {

	public GameOverView(final Activity activity, int style,
			final GameView gameView, final Dialog dialog, int gameViewStyle) {
		super(activity);
		View view;
		if (gameViewStyle == 1 && style == 1) {
			view = LayoutInflater.from(getContext()).inflate(
					R.layout.gameover_dialog2, null);
		} else {
			view = LayoutInflater.from(getContext()).inflate(
					R.layout.gameover_dialog, null);
			LinearLayout title = (LinearLayout) view
					.findViewById(R.id.game_title);
			int id = R.drawable.text_win;
			switch (style) {
			case 0:
				id = R.drawable.text_win;
				break;
			case 1:
				id = R.drawable.text_lose;
				break;
			case 2:
				id = R.drawable.text_same;
				break;
			default:
				break;
			}
			title.setBackgroundResource(id);
		}
		addView(view);

		Button ok = (Button) view.findViewById(R.id.btn_game_contunue);
		ok.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (gameView.gameMode == 1) {
					MyTimer.getInstance().initTotalTime();
				}
				gameView.roda = 0;
				gameView.placar1 = 0;
				gameView.placar2 = 0;
				postInvalidate();
				dialog.dismiss();
			}
		});
		Button cancel = (Button) view.findViewById(R.id.btn_game_over);
		cancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dialog.dismiss();
				activity.finish();
			}
		});
	}

}
